package com.v2.k6;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

//测试FactoryBean
@Component
public class TestFactoryBean implements FactoryBean<Object> {

	private static int count=0;

	// spring和mybatis整合的时候就是用了FactoryBean来生成代理对象
	// 相当于把一个对象放到spring容器中了
	@Override
	public Object getObject() throws Exception {

		Apple apple = new Apple();
		apple.setColor("红色");
		System.out.println("调用["+(++count)+"]次。。。");
		return apple;
	}

	@Override
	public Class<?> getObjectType() {
		return Apple.class;
	}

//	@Override
//	public boolean isSingleton() {  //来决定getBean是不是单例的
////		return false;
//		return true;
//	}
}
